package com.owen.controller;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class IndexController {

    @RequestMapping(value = "/goLoginInOne", method = RequestMethod.GET)
    public ModelAndView goLogin(ModelAndView modelAndView) {
        modelAndView.setViewName("login");
        modelAndView.addObject("jinshi", "请先登录");

        return modelAndView;
    }

    @RequestMapping(value = "/goLoginIn", method = RequestMethod.GET)
    public String goLogina() {
        return "login";
    }

    @RequestMapping(value = "/toIndex", method = RequestMethod.GET)
    public String toIndex() {
        return "index";
    }

    @RequestMapping(value = "/fenleilist", method = RequestMethod.GET)
    public String fenleilist() {
        return "fenlei/fenleilist";
    }

    @RequestMapping(value = "/fenlei/find/{id}", method = RequestMethod.GET)
    public String fenleilist(@PathVariable("id") Long id) {
        return "fenlei/find";
    }

    @RequestMapping(value = "/fenlei/fenleiupdate/{id}", method = RequestMethod.GET)
    public String fenleiupdate(@PathVariable("id") Long id) {
        return "fenlei/fenleiupdate";
    }

    @RequestMapping(value = "/orderlist", method = RequestMethod.GET)
    public String orderlist() {
        return "order/orderlist";
    }

    @RequestMapping(value = "/orderView/{id}", method = RequestMethod.GET)
    public String orderView(@PathVariable("id") Integer id) {
        return "order/orderView";
    }

    @RequestMapping(value = "/userlist", method = RequestMethod.GET)
    public String userlist() {
        return "user/userlist";
    }

    @RequestMapping(value = "/addFenlei", method = RequestMethod.GET)
    public String addFenlei() {
        return "fenlei/fenleiadd";
    }

    @RequestMapping(value = "/passwordupdate", method = RequestMethod.GET)
    public String passwordupdate() {
        return "updatepassword";
    }

    @RequestMapping(value = "/loginout", method = RequestMethod.GET)
    public String loginout(HttpServletRequest req) {
        HttpSession session = req.getSession();
        session.removeAttribute("login");


//        //不对页面进行缓存，再次访问时将从服务器重新获取最新版本
//        response.header("Cache-Control","no-cache");
//        //任何情况下都不缓存页面
//        response.header("Cache-Control","no-store");
//        //使缓存过期
////        response.setDateHeader("Expires", 0);
////        response.header("Expires", 0);
//        //HTTP 1.0 向后兼容
//        response.header("Pragma","no-cache");



        return "login";
    }

    @RequestMapping(value = "/productlist", method = RequestMethod.GET)
    public String productlist() {
        return "product/productlist";
    }

    @RequestMapping(value = "/addProduct", method = RequestMethod.GET)
    public String addProduct() {
        return "product/productadd";
    }

    @RequestMapping(value = "/productView/{id}", method = RequestMethod.GET)
    public String productView(@PathVariable("id") Integer id) {
        return "product/productView";
    }

    @RequestMapping(value = "/productupdate/{id}", method = RequestMethod.GET)
    public String productupdate(@PathVariable("id") Integer id) {
        return "product/productupdate";
    }

    @RequestMapping(value = "/supplierList", method = RequestMethod.GET)
    public String supplierList() {
        return "supplier/supplierlist";
    }

    @RequestMapping(value = "/toAddSupplier", method = RequestMethod.GET)
    public String toAddSupplier() {
        return "supplier/supplieradd";
    }

    @RequestMapping(value = "/toSupplierView/{id}", method = RequestMethod.GET)
    public String toSupplierView(@PathVariable("id") Integer id) {
        return "supplier/supplierView";
    }

    @RequestMapping(value = "/toSupplierUpdate/{id}", method = RequestMethod.GET)
    public String toSupplierUpdate(@PathVariable("id") Integer id) {
        return "supplier/supplierupdate";
    }

    @RequestMapping(value = "/toVegetablesView/{id}", method = RequestMethod.GET)
    public String toVegetablesView(@PathVariable("id") Integer id) {
        return "vegetables/vegetablesView";
    }

    @RequestMapping(value = "/toVegetablesUpdate/{id}", method = RequestMethod.GET)
    public String toVegetablesUpdate(@PathVariable("id") Integer id) {
        return "vegetables/vegetablesUpdate";
    }

    @RequestMapping(value = "/vegetablesList", method = RequestMethod.GET)
    public String vegetablesList() {
        return "vegetables/vegetableslist";
    }

    @RequestMapping(value = "/toAddVegetables", method = RequestMethod.GET)
    public String toAddVegetables() {
        return "vegetables/vegetablesadd";
    }

    @RequestMapping(value = "/toZhuce")
    public String toZhuce() {
        return "zhuce";
    }

    @RequestMapping(value = "/commoditylist")
    public String commoditylist(){
        return "commodity/commoditylist";
    }

    @RequestMapping(value = "/commoditieView/{id}")
    public String commoditieView(@PathVariable("id") Integer id){
        return "commodity/commodityView";
    }

    @RequestMapping(value = "/commoditieupdate/{id}")
    public String commoditieupdate(@PathVariable("id") Integer id){
        return "commodity/commodityUpdate";
    }

    @RequestMapping(value = "/addCommodity")
    public String addCommodity(){
        return "commodity/commodityadd";
    }

    @RequestMapping(value = "/fruitslist")
    public String toFruitslist(){
        return "fruits/fruitslist";
    }

    @RequestMapping(value = "/fruits/fruitsView/{id}")
    public String toFruitsView(@PathVariable("id") Integer id){
        return "fruits/fruitsView";
    }

    @RequestMapping(value = "/fruits/fruitsUpdate/{id}")
    public String toFruitsUpdate(@PathVariable("id") Integer id){
        return "fruits/fruitsupdate";
    }

    @RequestMapping(value = "/addFruits")
    public String toAddFruits(){
        return "fruits/fruitsadd";
    }

    @RequestMapping(value = "/cakelist")
    public String tocakelist(){
        return "cake/cakelist";
    }

    @RequestMapping(value = "/cakeView/{id}")
    public String toCakeView(@PathVariable("id") Integer id){
        return "cake/cakeView";
    }

    @RequestMapping(value = "/cakeupdate/{id}")
    public String toCakeUpdate(@PathVariable("id") Integer id){
        return "cake/cakeUpdate";
    }

    @RequestMapping(value = "/addCake")
    public String addCake(){
        return "cake/cakeadd";
    }

}
